let wrap = document.getElementById('#wrap')
let swiper = wrap.children[0]
let lis = swiper.children
let imgWidth = swiper.offsetWidth

let rgt = document.getElementsById('rigth')
let lft = document.getElementById('left')


let pic = 0

var timeId = setInterval(rightClick, 3000)

function rightClick() {
    if (pic === lis.length - 1) {
        pic = 0
        swiper.style.left = 0 + 'px'
    }
    pic++
    // 调用函数
    animate(swiper, -pic * imgWidth)
}

function animate(element, target) {
    clearInterval(element.timeId)
    element.timeId = setInterval(() => {
        let current = element.offsetLeft
        let step = 10
        step = current < target ? step : -step
        current += step
        if (Math.abs(target - current)) {
            element.style.left = current + 'px'
        } else {
            clearInterval(element.timeId)
            element.style.left = target + 'px'
        }

    }, 5)

}
